<?php
defined('BY_JYA') or exit('error');
$_RQ['op']=$_RQ['op']?$_RQ['op']:'edit';
$return=array();
if($_RQ['op']=='edit'){
	if($merchid){
		$item=$this->pdo_get('merch',array('id'=>$merchid));
	}else{
		$item=array();
	}
	$item['upass']='';
    $return['item']=$item;
	$htmls=array( 
		'type'=>'edit',
		'post'=>'post',
		'desc'=>'商户设置',
		'tabs'=>array(
			array('op'=>'edit','title'=>'商户设置'),
		),
		'edit'=>array(
			array('name'=>'title','must'=>true,'title'=>'商户名称','type'=>'string'),
			array('name'=>'logo','title'=>'商户logo','type'=>'image'),
			//array('name'=>'agent_id','title'=>'绑定代理商','type'=>'choose','action'=>'get_merch'),
			//array('name'=>'mid','title'=>'绑定管理员','type'=>'choose','action'=>'core/member.get_member/'),
			array('type'=>'string','title'=>'昵称','name'=>'nickname'),
			array('name'=>'realname','title'=>'真实姓名','type'=>'string'),
			array('name'=>'mobile','title'=>'手机号','type'=>'string'),
			array('name'=>'upass','title'=>'账户密码','type'=>'string'),
			array('name'=>'sex','title'=>'性别','type'=>'radio','options'=>'sex'),
		)
	);
	$return['status']=array('0'=>'待审核','1'=>'入驻中','2'=>'暂停中');
	$return['sex']=array('1'=>'男','2'=>'女');
	$return['htmls']=$htmls;
	exi($return);
}
if($_RQ['op']=='post'){
	$post=get_postdata();
	if(!$post['title']){
		exi('商户名称必填','error');
	}
	$data =array(
		'upass'=>base64_encode($post['upass']),
		'mobile'=>$post['mobile'],
		'realname'=>$post['realname'],
		'title'=>$post['title'],
		'logo'=>$post['logo'],
		'sex'=>intval($post['sex']),
		'nickname'=>$post['nickname'],
		'mobile'=>$post['mobile'],
		'realname'=>$post['realname'],
	);
	if($post['id']){
		if(!$post['upass']){
			unset($data['upass']);
		}
		$this->pdo_update('merch',$data,array('id'=>$post['id']));
		exi('保存成功','','list');
	}else{
		$data['uniacid']=$_SESSION['uniacid'];
		$data['mid']=$_SESSION['uid'];
		$data['createtime']=time();
		$this->pdo_insert('merch',$data);
		exi('添加成功','','list');
	}
	
}
if($_RQ['op']=='del'){
	$id=intval($_RQ['id']);
	if(!$id){
		exi('请选择商户！！','error');
	}
	$del=trim($_RQ['del'],';');
	if($del){
		$del=explode(';',$del);
		foreach($del as $id){
			$id=intval($id);
			if($id){
				$this->pdo_delete('merch',array('uniacid'=>$_SESSION['uniacid'],'id'=>$id));
			}
		}
	}
	exi('删除成功！');
}
?>